﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClipperHouse.jQuery.Base
{
	/// <summary>
	/// Base (helper) class for effects that accept a single "Speed" parameter. This includes show/hide, fadeIn/Out, slide and others
	/// See http://docs.jquery.com/Effects
	/// </summary>
	public abstract class JQueryWithSpeed : JQuery
	{
		protected const string speedParamName = "Speed";
		
		public JQueryWithSpeed()
		{
			this.SpeedIfRequired = String.Empty;

			// Ensure that Speed is the first param
			Params.Clear();
			Params.Add(speedParamName, String.Empty);
		}

		protected string SpeedIfRequired { get; set; }

		/// <summary>
		/// A string representing one of the three predefined speeds ("slow", "normal", or "fast") or the number of milliseconds to run the animation (e.g. 1000).
		/// (taken from jQuery docs at: http://docs.jquery.com/Effects)
		/// </summary>
		public string Speed
		{
			get
			{
				return Params[speedParamName];
			}
			set
			{
				Params[speedParamName] = (string)value;
			}
		}

		public override void OnCallbackSet(InnerProperty callback)
		{
			if (!String.IsNullOrEmpty(callback.Text.Trim()) && String.IsNullOrEmpty(this.Speed))
			{
				this.Speed = SpeedIfRequired;
			}
		}

	}
}
